package com.ruoyi.web.controller.gas;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.gas.service.IGasCompanyService;
import com.ruoyi.gas.service.IGasDeviceService;
import com.ruoyi.gas.service.IGasEventService;
import com.ruoyi.gas.service.IGasWarnRectifyService;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName 数据大屏接口
 * @Description TODO
 * @Author ZYJ
 * @Date 2024/1/2 9:49
 * @Version 1.0
 **/
@RestController
@RequestMapping("/gas/screen")
public class BigScreenController extends BaseController {

    @Autowired
    private IGasDeviceService gasDeviceService;

    @Autowired
    private IGasWarnRectifyService gasWarnRectifyService;

    @Autowired
    private IGasCompanyService gasCompanyService;


    /**
     * 获取气体探测器历年趋势
     * @return
     */
    @GetMapping("/getDeviceCountTrend")
    public AjaxResult getDeviceCountTrend(){
        List<Map<String, Object>> list = gasDeviceService.getDeviceCountTrend();
        return AjaxResult.success(list);
    }

    /**
     * 获取气体预警趋势
     * @param type  1日 2周 3月 4年
     * @return
     */
    @GetMapping("/getWarnCountTrend")
    public AjaxResult getWarnCountTrend(int type){
        List<Map<String, Integer>> list = gasWarnRectifyService.getWarnCountTrend(type);
        return AjaxResult.success(list);
    }

    /**
     * 获取大屏顶部数量信息
     * 企业总数 监管设备 在线设备 离线设备 预警数量
     * @return
     */
    @GetMapping("/getTopCount")
    public AjaxResult getTopCount(){
        int company = gasCompanyService.getCompanyCounts();
        int device = gasDeviceService.getCountByType(0);
        int online = gasDeviceService.getCountByType(3);
        int offline = gasDeviceService.getCountByType(4);
        int warn = gasWarnRectifyService.getWarnCounts();

        Map<String,Integer> map=new HashMap<>();
        map.put("company",company);
        map.put("device",device);
        map.put("online",online);
        map.put("offline",offline);
        map.put("event",warn);

        return AjaxResult.success(map);
    }

    /**
     * 获取大屏底部柱状图数据
     * @param type 1月 2周
     * @return
     */
    @GetMapping("/getBottomCount")
    public AjaxResult getBottomCount(int type){
        Map<String,Object> map=new HashMap<>();
        List<Map<String, Integer>> pcList = gasWarnRectifyService.getBottomCount(type, 1);
        List<Map<String, Integer>> xcList = gasWarnRectifyService.getBottomCount(type, 2);

        map.put("pc",pcList);
        map.put("xc",xcList);

        return AjaxResult.success(map);
    }

    /**
     * 报警治理情况
     * @return
     */
    @GetMapping("/getGovern")
    public AjaxResult getGovern(){
        Map<String,Integer> map=new HashMap<>();

        int xc = gasWarnRectifyService.getGovern();

        map.put("pc",100);
        map.put("xc",xc);

        return AjaxResult.success(map);
    }

    /**
     * 报警治理情况详情
     * @return
     */
    @GetMapping("/getGovernDetail")
    public AjaxResult getGovernDetail(){
        List<Map<String, Object>> list = gasWarnRectifyService.getGovernDetail();

        return AjaxResult.success(list);
    }

    /**
     * 获取预警情况
     * @return
     */
    @GetMapping("/getEventList")
    public AjaxResult getEventList(){
        List<Map<String, Object>> list = gasWarnRectifyService.getWarnList();

        return AjaxResult.success(list);
    }



//    -----------------------------------企业大屏-----------------------------------


    /**
     * 查询每日预警数量
     * @param companyId 企业Id
     * @return
     */
    @GetMapping("/getDailyEventCount")
    public AjaxResult getDailyEventCount(Long companyId){
        List<Map<String, Object>> list = gasWarnRectifyService.getDailyEventCount(companyId);

        return AjaxResult.success(list);
    }

    /**
     * 查询企业大屏顶部各分类数量信息
     * @param companyId
     * @return
     */
    @GetMapping("/getCompanyTop")
    public AjaxResult getCompanyTop(Long companyId){
        int device = gasDeviceService.getCompanyTop(companyId, null);
        int zxDevice = gasDeviceService.getCompanyTop(companyId, 3);
        int lxDevice = gasDeviceService.getCompanyTop(companyId, 4);
        Map<String, Integer> map = gasWarnRectifyService.getCompanyWarnCount(companyId);
        map.put("device",device);
        map.put("zxDevice",zxDevice);
        map.put("lxDevice",lxDevice);

        return AjaxResult.success(map);
    }

    /**
     * 获取大屏底部柱状图数据
     * @param type 1月 2周
     * @return
     */
    @GetMapping("/getCompanyBottom")
    public AjaxResult getCompanyBottom(Long companyId,Integer type){
        Map<String,Object> map=new HashMap<>();
        List<Map<String, Integer>> pcList = gasWarnRectifyService.getCompanyBottom(companyId,type, 1);
        List<Map<String, Integer>> xcList = gasWarnRectifyService.getCompanyBottom(companyId,type, 2);

        map.put("pc",pcList);
        map.put("xc",xcList);

        return AjaxResult.success(map);
    }

    /**
     * 报警治理情况
     * @return
     */
    @GetMapping("/getCompanyGovern")
    public AjaxResult getCompanyGovern(Long companyId){
        Map<String,Integer> map=new HashMap<>();

        int xc = gasWarnRectifyService.getCompanyGovern(companyId);

        map.put("pc",100);
        map.put("xc",xc);

        return AjaxResult.success(map);
    }

    /**
     * 报警治理情况
     * @return
     */
    @GetMapping("/getCompanyGovernDetail")
    public AjaxResult getCompanyGovernDetail(Long companyId){
        Map<String,Integer> map=new HashMap<>();

        List<Map<String, Object>> list = gasWarnRectifyService.getCompanyGovernDetail(companyId);

        return AjaxResult.success(list);
    }

    /**
     * 获取企业预警情况
     * @return
     */
    @GetMapping("/getCompanyEventList")
    public AjaxResult getCompanyEventList(Long companyId){
        List<Map<String, Object>> list = gasWarnRectifyService.getCompanyEventList(companyId);

        return AjaxResult.success(list);
    }
}
